import { computed, ref } from 'vue';
import { catecfg } from '@/common/api/hbMarket';

interface CategoryItem {
  cateimg: string;
  catename: string;
}

export function useCategoryList() {
  const categoryList = ref<CategoryItem[]>([]);
  const categoryOpt = computed(() => categoryList.value.map((v) => ({ text: v.catename, value: v.catename })));

  const onLoad = async () => {
    try {
      const res = await catecfg({});
      const data = res.result.data;
      categoryList.value = data.category;
    } catch {
      /** empty */
    }
  };
  onLoad();

  return { categoryList, categoryOpt };
}
